package com.wyhello.tube4.spring.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.wyhello.tube4.pojo.Bag;
import com.wyhello.tube4.pojo.Macroscopic;
import com.wyhello.tube4.pojo.Reality;
import com.wyhello.tube4.pojo.Reside;
import com.wyhello.tube4.pojo.Tube;
import com.wyhello.tube4.spring.model.AnalysisDrawModel;
import com.wyhello.tube4.spring.model.BagRecordsModel;
import com.wyhello.tube4.spring.model.MeterRecordsModel;
import com.wyhello.tube4.spring.model.ResideRecordsModel;

@Controller
public class BoilerDrawController {
	@Autowired
	private AnalysisDrawModel analysisDrawModel;
	
	@Autowired
	private ResideRecordsModel resideRecordsModel;
	
	@Autowired
	private BagRecordsModel bagRecordsModel;
	
	@Autowired
	private MeterRecordsModel meterRecordsModel;
	
	
	/**
	 * 查询锅炉信息
	 * @return
	 */
	@RequestMapping("/pie/queryRealitys")
	public ModelAndView queryRealitys(){
		List<Reside> boilers =  meterRecordsModel.queryResideByBoiler();
		ModelAndView model = new ModelAndView("main");
		model.addObject("boilers",boilers);
		return model;
	}
	/**
	 * 查询指定锅炉下的受热面
	 * @param parentid
	 * @return
	 */
	@RequestMapping("/pie/querySurface")
	public void querySurface(int parentid,HttpServletResponse response){
		Reside reside = resideRecordsModel.getResideById(parentid);
		Set<Reside> surfaceSet = reside.getResides();
		Map<Integer,String> map = new TreeMap<Integer,String>();
		for (Reside surface : surfaceSet) {
			map.put(surface.getId(), surface.getName());
		}
		JSONObject json = JSONObject.fromObject(map);
		PrintWriter out = null;
		try {
			response.setCharacterEncoding("UTF-8");
			out = response.getWriter();
		} catch (IOException e) {
			e.printStackTrace();
		}
		out.print(json);
	}
	/**
	 * 查询指定受热面下的管排
	 * @param parentid
	 * @return
	 */
	@RequestMapping("/pie/queryRows")
	public void queryRows(int parentid,HttpServletResponse response){
		Reside reside = resideRecordsModel.getResideById(parentid);
		Set<Reside> rows = reside.getResides();
		Map<Integer,String> map = new TreeMap<Integer,String>();
		for (Reside row : rows) {
			map.put(row.getId(), row.getName());
		}
		JSONObject json = JSONObject.fromObject(map);
		PrintWriter out = null;
		try {
			response.setCharacterEncoding("UTF-8");
			out = response.getWriter();
		} catch (IOException e) {
			e.printStackTrace();
		}
		out.print(json);
	}
	/**
	 * 查询指定管排下的管
	 * @param parentid
	 * @return
	 */
	@RequestMapping("/pie/queryTube")
	public void queryRow(int parentid,HttpServletResponse response){
		Reside reside = resideRecordsModel.getResideById(parentid);
		Set<Tube> tubes = reside.getTubes();
		Map<Integer,String> map = new TreeMap<Integer,String>();
		for (Tube tube : tubes) {
			map.put(tube.getId(), tube.getName());
		}
		JSONObject json = JSONObject.fromObject(map);
		PrintWriter out = null;
		try {
			response.setCharacterEncoding("UTF-8");
			out = response.getWriter();
		} catch (IOException e) {
			e.printStackTrace();
		}
		out.print(json);
	}
	
	/**
	 * 管排横向蠕胀饼图
	 * @param rowId
	 * @return
	 */
	@RequestMapping("/pie/queryRowRZX")
	public ModelAndView queryRowRZX(int rowId){
		ModelAndView model =  analysisDrawModel.getRealityPieRow("creepValueX", "creepWarnValue", rowId);
		return model;
	}
	
	/**
	 * 管排纵向蠕胀饼图
	 * @param rowId
	 * @return
	 */
	@RequestMapping("/pie/queryRowRZY")
	public ModelAndView queryRowRZY(int rowId){
		ModelAndView model =  analysisDrawModel.getRealityPieRow("creepValueY", "creepWarnValue", rowId);
		return model;
	}
	
	/**
	 * 管排磨损饼图
	 * @param rowId
	 * @return
	 */
	@RequestMapping("/pie/queryRowMS")
	public ModelAndView queryRowMS(int rowId){
		ModelAndView model =  analysisDrawModel.getRealityPieRow("wearRate", "speedValue", rowId);
		return model;
	}
	
	
	/**
	 * 管排寿命饼图
	 * @param rowId
	 * @return
	 */
	@RequestMapping("/pie/queryRowSM")
	public ModelAndView queryRowSM(int rowId){
		ModelAndView model =  analysisDrawModel.getRealityPieRow("lifetime", "lifeValue", rowId);
		return model;
	}
	
	/**
	 * 受热面横向蠕胀饼图
	 * @param resideId
	 * @return
	 */
	@RequestMapping("/pie/querySurfaceRZX")
	public ModelAndView querySurfaceRZX(int surfaceId){
		ModelAndView model =  analysisDrawModel.getRealityPieSurface("creepValueX", "creepWarnValue", surfaceId);
		return model;
	}
	
	/**
	 * 受热面纵向蠕胀饼图
	 * @param resideId
	 * @return
	 */
	@RequestMapping("/pie/querySurfaceRZY")
	public ModelAndView querySurfaceRZY(int surfaceId){
		ModelAndView model =  analysisDrawModel.getRealityPieSurface("creepValueY", "creepWarnValue", surfaceId);
		return model;
	}
	
	/**
	 * 受热面磨损饼图
	 * @param resideId
	 * @return
	 */
	@RequestMapping("/pie/querySurfaceMS")
	public ModelAndView querySurfaceMS(int surfaceId){
		ModelAndView model =  analysisDrawModel.getRealityPieSurface("wearRate", "speedValue", surfaceId);
		return model;
	}
	
	
	/**
	 * 受热面寿命饼图
	 * @param resideId
	 * @return
	 */
	@RequestMapping("/pie/querySurfaceSM")
	public ModelAndView querySurfaceSM(int surfaceId){
		ModelAndView model =  analysisDrawModel.getRealityPieSurface("lifetime", "lifeValue", surfaceId);
		return model;
	}
	
	/**
	 * 受热面宏观磨损
	 * @param resideId
	 * @return
	 */
	@RequestMapping("/pie/querySurfaceMacrosMS")
	public ModelAndView querySurfaceMacrosMS(int surfaceId){
		ModelAndView model =  analysisDrawModel.getMacroscopicPieSurface("abrade", surfaceId);
		return model;
	}
	
	/**
	 * 受热面宏观冲刷
	 * @param resideId
	 * @return
	 */
	@RequestMapping("/pie/querySurfaceMacrosCS")
	public ModelAndView querySurfaceMacrosCS(int surfaceId){
		ModelAndView model =  analysisDrawModel.getMacroscopicPieSurface("wash", surfaceId);
		return model;
	}
	
	/**
	 * 受热面宏观过热
	 * @param resideId
	 * @return
	 */
	@RequestMapping("/pie/querySurfaceMacrosGR")
	public ModelAndView querySurfaceMacrosGR(int surfaceId){
		ModelAndView model =  analysisDrawModel.getMacroscopicPieSurface("superheat", surfaceId);
		return model;
	}
	
	/**
	 * 受热面宏观腐蚀
	 * @param resideId
	 * @return
	 */
	@RequestMapping("/pie/querySurfaceMacrosFS")
	public ModelAndView querySurfaceMacrosFS(int surfaceId){
		ModelAndView model =  analysisDrawModel.getMacroscopicPieSurface("corrode", surfaceId);
		return model;
	}
	
	/**
	 * 受热面宏观变形
	 * @param resideId
	 * @return
	 */
	@RequestMapping("/pie/querySurfaceMacrosBX")
	public ModelAndView querySurfaceMacrosBX(int surfaceId){
		ModelAndView model =  analysisDrawModel.getMacroscopicPieSurface("transformation", surfaceId);
		return model;
	}
	
	/**
	 * 锅炉横向蠕胀饼图
	 * @param boilerId
	 * @return
	 */
	@RequestMapping("/pie/queryBoilerRZX")
	public ModelAndView queryBoilerRZX(int boilerId){
		ModelAndView model =  analysisDrawModel.getRealityPieBoiler("creepValueX", "creepWarnValue", boilerId);
		return model;
	}
	
	/**
	 * 锅炉纵向蠕胀饼图
	 * @param boilerId
	 * @return
	 */
	@RequestMapping("/pie/queryBoilerRZY")
	public ModelAndView queryBoilerRZY(int boilerId){
		ModelAndView model =  analysisDrawModel.getRealityPieBoiler("creepValueY", "creepWarnValue", boilerId);
		return model;
	}
	
	/**
	 * 锅炉磨损饼图
	 * @param boilerId
	 * @return
	 */
	@RequestMapping("/pie/queryBoilerMS")
	public ModelAndView queryBoilerMS(int boilerId){
		ModelAndView model =  analysisDrawModel.getRealityPieBoiler("wearRate", "speedValue", boilerId);
		return model;
	}
	
	
	/**
	 * 锅炉寿命饼图
	 * @param boilerId
	 * @return
	 */
	@RequestMapping("/pie/queryBoilerSM")
	public ModelAndView queryBoilerSM(int boilerId){
		ModelAndView model =  analysisDrawModel.getRealityPieBoiler("lifetime", "lifeValue", boilerId);
		return model;
	}
	
	/**
	 * 锅炉宏观磨损
	 * @param boilerId
	 * @return
	 */
	@RequestMapping("/pie/queryBoilerMacrosMS")
	public ModelAndView queryBoilerMacrosMS(int boilerId){
		ModelAndView model =  analysisDrawModel.getMacroscopicPieBoiler("abrade", boilerId);
		return model;
	}
	
	/**
	 * 锅炉宏观冲刷
	 * @param boilerId
	 * @return
	 */
	@RequestMapping("/pie/queryBoilerMacrosCS")
	public ModelAndView queryBoilerMacrosCS(int boilerId){
		ModelAndView model =  analysisDrawModel.getMacroscopicPieBoiler("wash", boilerId);
		return model;
	}
	
	
	/**
	 * 锅炉宏观过热
	 * @param boilerId
	 * @return
	 */
	@RequestMapping("/pie/queryBoilerMacrosGR")
	public ModelAndView queryBoilerMacrosGR(int boilerId){
		ModelAndView model =  analysisDrawModel.getMacroscopicPieBoiler("superheat", boilerId);
		return model;
	}
	
	/**
	 * 锅炉宏观腐蚀
	 * @param boilerId
	 * @return
	 */
	@RequestMapping("/pie/queryBoilerMacrosFS")
	public ModelAndView queryBoilerMacrosFS(int boilerId){
		ModelAndView model =  analysisDrawModel.getMacroscopicPieBoiler("corrode", boilerId);
		return model;
	}
	
	/**
	 * 锅炉宏观变形
	 * @param boilerId
	 * @return
	 */
	@RequestMapping("/pie/queryBoilerMacrosBX")
	public ModelAndView queryBoilerMacrosBX(int boilerId){
		ModelAndView model =  analysisDrawModel.getMacroscopicPieBoiler("transformation", boilerId);
		return model;
	}
	
	
	
	/**
	 * 查询管占管排百分比宏观磨损
	 * @param resideId
	 * @return
	 */
	@RequestMapping("/pie/queryRowMacrosMS")
	public ModelAndView queryRowMacrosMS(int rowId){
		ModelAndView model =  analysisDrawModel.getMacroscopicPieRow("abrade", rowId);
		return model;
	}
	
	
	/**
	 * 查询管占管排百分比宏观冲刷
	 * @param resideId
	 * @return
	 */
	@RequestMapping("/pie/queryRowMacrosCS")
	public ModelAndView queryRowMacrosCS(int rowId){
		ModelAndView model =  analysisDrawModel.getMacroscopicPieRow("wash", rowId);
		return model;
	}
	
	
	/**
	 * 查询管占管排百分比宏观过热
	 * @param resideId
	 * @return
	 */
	@RequestMapping("/pie/queryRowMacrosGR")
	public ModelAndView queryRowMacrosGR(int rowId){
		ModelAndView model =  analysisDrawModel.getMacroscopicPieRow("superheat", rowId);
		return model;
	}
	
	
	/**
	 * 管排宏观腐蚀
	 * @param resideId
	 * @return
	 */
	@RequestMapping("/pie/queryRowMacrosFS")
	public ModelAndView queryRowMacrosFS(int rowId){
		ModelAndView model =  analysisDrawModel.getMacroscopicPieRow("corrode", rowId);
		return model;
	}
	
	
	/**
	 * 管排宏观变形
	 * @param resideId
	 * @return
	 */
	@RequestMapping("/pie/queryRowMacrosBX")
	public ModelAndView queryRowMacrosBX(int rowId){
		ModelAndView model =  analysisDrawModel.getMacroscopicPieRow("transformation", rowId);
		return model;
	}
}
